package com.qboot.generate.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.qboot.common.controller.BaseController;
import com.qboot.common.entity.Result;
import com.qboot.common.entity.TableResult;
import com.qboot.generate.service.GenTableColumnService;
import com.qboot.generate.vo.GenTableColumnVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 代码生成-字段 控制层
 *
 * @author Tellsea
 * @date 2022-11-25
 */
@Api(tags = "代码生成-字段 控制层")
@RestController
@RequestMapping("/generate/genTableColumn")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class GenTableColumnController extends BaseController {

    private final GenTableColumnService genTableColumnService;

    @ApiOperation("查询列表")
    @SaCheckPermission("generate:genTableColumn:list")
    @GetMapping("/list")
    public TableResult<GenTableColumnVo> queryList(GenTableColumnVo entity) {
        return TableResult.ok(genTableColumnService.queryList(getPage(), entity));
    }

    @ApiOperation("根据主键查询")
    @SaCheckPermission("generate:genTableColumn:get")
    @GetMapping("/queryById/{id}")
    public Result<GenTableColumnVo> queryById(@PathVariable("id") Long id) {
        return queryResult(genTableColumnService.queryById(id));
    }

    @ApiOperation("新增")
    @SaCheckPermission("generate:genTableColumn:save")
    @PostMapping("/save")
    public Result save(@RequestBody GenTableColumnVo entity) {
        return saveResult(genTableColumnService.save(entity));
    }

    @ApiOperation("根据主键更新")
    @SaCheckPermission("generate:genTableColumn:update")
    @PostMapping("/updateById")
    public Result updateById(@RequestBody GenTableColumnVo entity) {
        return updateResult(genTableColumnService.updateById(entity));
    }

    @ApiOperation("根据主键删除")
    @SaCheckPermission("generate:genTableColumn:remove")
    @GetMapping("/removeById/{id}")
    public Result removeById(@PathVariable("id") Long id) {
        return removeResult(genTableColumnService.removeById(id));
    }
}
